use std::sync::Arc;

use crate::transport::webrtc::{create_accept_channel, create_follower_channel};

use super::{WebRTCDialMessage, WebRTCDialResponseMessage, WebRTCMessage};

pub async fn on_message(
    peer_id: &String,
    message: &WebRTCMessage,
) -> anyhow::Result<Option<String>> {
    //
    match message {
        WebRTCMessage::Dial(msg) => _dial(peer_id, msg).await,
        WebRTCMessage::DialResponse(msg) => _dial_response(peer_id, msg).await,
        _ => {
            tracing::debug!("");
            Ok(None)
        }
    }
}

async fn _dial(peer_id: &String, message: &WebRTCDialMessage) -> anyhow::Result<Option<String>> {
    //创建连接
    let remote_candidates = &message.candidates;

    let arc = create_accept_channel(peer_id, remote_candidates, &message.local_description).await?;

    Ok(None)
}

async fn _dial_response(
    peer_id: &String,
    message: &WebRTCDialResponseMessage,
) -> anyhow::Result<Option<String>> {
    //创建连接
    let remote_candidates = &message.candidates;

    let arc =
        create_follower_channel(peer_id, remote_candidates, &message.local_description).await?;
    //返回
    Ok(None)
}
